<template>
    <div>
        <van-search v-model="value" placeholder="请输入搜索关键词" @update:model-value="toArray" />

        <van-card v-for="(v, i) in list" :key="i" :price="v.goods_price" :title="v.goods_name"
        @click="todetail(v.goods_id)">
            <template #thumb>
                <img :src="v.goods_small_logo ? v.goods_small_logo : 'https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg'"
                    alt="" style="width: 6rem;height: 6rem;">
            </template>
        </van-card>

    </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRoute, useRouter } from 'vue-router'
const router = useRouter()
const route = useRoute()
import { searchApi } from '@/api/api';

let value = ref(route.query.name)
let list = ref([])
const getlist = () => {
    searchApi(value.value).then((res) => {
        console.log(res);
        list.value = res.data.message.goods
    })
}
getlist()


const toArray = () =>{
    getlist()
}

const todetail = (id) =>{
    router.push({path:'/detail',query:{id:id}})
}
</script>

<style lang="scss" scoped></style>